﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using BaseData.Exts;

namespace BaseData.Lib
{
    public class DbContextFactory
    {
        #region - 获取当前线程的读取上下文对象-

        /// <summary>
        /// 获取当前线程的读取上下文对象
        /// </summary>
        /// <returns></returns>
        public static ContextExt GetDbContext()
        {
            ContextExt result = null;
            var context = CallContext.GetData(string.Format("read 4 :{0}", typeof(ContextExt).AssemblyQualifiedName));
            if (context == null || (context as ContextExt) == null)
            {
                result = new ContextExt();
                CallContext.SetData(string.Format("read 4 :{0}", typeof(ContextExt).AssemblyQualifiedName), result);
            }
            else
            {
                result = context as ContextExt;
            }
            return result;
        }

        #endregion
    }
}
